package com.dasel.math

/**
 * Created by IntelliJ IDEA.
 * User: benoit
 * Date: 28-Feb-2010
 * Time: 18:12:22
 * To change this template use File | Settings | File Templates.
 */
@Typed
class Srid<T extends Number> {
    Integer rows
    Integer cols
    T[][] matrix

    Srid<T> plus(Srid<T> right) {
        if (rows != right.rows) throw new Exception("Matrix A and Matrix B must be same size");
        T[][] results = new T[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] + right.matrix[i][j]
            }
        }
        return new Srid(matrix: results, rows: rows, cols: cols)
    }


    Srid<T> plus(Number right) {
        T[][] results = new T[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] + right
            }
        }
        return new Srid(matrix: results, rows: rows, cols: cols)
    }

     Srid<T> multiply(Srid<T> right) {
        if (rows != right.rows) throw new Exception("Matrix A and Matrix B must be same size");
        T[][] results = new T[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] * right.matrix[i][j]
            }
        }
        return new Srid(matrix: results, rows: rows, cols: cols)
    }


    Srid<T> multiply(Number right) {
        T[][] results = new T[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] * right
            }
        }
        return new Srid(matrix: results, rows: rows, cols: cols)
    }
}
